fix: use asyncio.Event() for thread-safe initialization state#2383
Merged
juanmichelini merged 9 commits intoOpenHands:mainfrom Mar 23, 2026
Merged
Conversation
…outer Replace the plain boolean _initialization_complete flag with asyncio.Event() for more idiomatic async code in an async application. Changes: - _initialization_complete = False → asyncio.Event() - mark_initialization_complete() → calls .set() instead of assigning True - ready() endpoint → uses .is_set() instead of truthiness check - Add tests for the /ready endpoint before and after initialization This makes the initialization signal explicit and async-friendly, avoiding any footgun from accidentally awaiting a bool in the future. No behaviour change is expected from existing callers. Closes OpenHands#1825 Co-authored-by: openhands <openhands@all-hands.dev>
Collaborator
|
[Automatic Post]: It has been a while since there was any activity on this PR. @ixchio, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
Collaborator
|
[Automatic Post]: I have assigned @juanmichelini as a reviewer based on git blame information. Thanks in advance for the help! |
juanmichelini
approved these changes
Mar 23, 2026
Collaborator
juanmichelini
left a comment
There was a problem hiding this comment.
LGTM, good fix and tested!
Collaborator
|
@ixchio thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1825
Replaces the plain boolean
_initialization_completeflag inserver_details_router.pywithasyncio.Event(), making the initialization signal explicit and idiomatic for async code.Changes
_initialization_complete = False→asyncio.Event()mark_initialization_complete()now calls.set()instead of assigningTrue/readyendpoint now uses.is_set()instead of a truthiness check/readyendpoint covering both pre- and post-initialization statesWhy asyncio.Event()?
While Python's GIL protects simple boolean assignments,
asyncio.Event()communicates intent clearly:await _initialization_complete.wait()if neededboolTesting
All existing tests pass. New tests added in
tests/agent_server/test_server_details_router.py: